<template>
  <a-modal
    title="分包商出场设置"
    :width="800"
    :visible="visible"
    :confirmLoading="loading">
    <template slot="footer">
      <a-button @click="() => { $emit('cancel') }">
        取消
      </a-button>
      <a-button key="submit" type="primary" @click="() => { $emit('ok') }">
        确定出场
      </a-button>
    </template>
    <a-spin :spinning="loading">
      <a-form :form="form" v-bind="formLayout">
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-item
              label="分公司"
              :labelCol="{lg: {span: 7}, sm: {span:7}}"
              :wrapperCol="{lg: {span: 17}, sm: {span: 17} }">
              <BaseInput v-decorator="['branch',{rules: [{   message: ' ' }]}]" disabled></BaseInput>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-item
              label="项目"
              :labelCol="{lg: {span: 7}, sm: {span: 7}}"
              :wrapperCol="{lg: {span:17}, sm: {span: 17} }">
              <BaseInput  v-decorator="['projectName',{rules: [{   message: ' ' }]}]" disabled></BaseInput>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-item
              label="分包商名称"
              :labelCol="{lg: {span: 7}, sm: {span: 7}}"
              :wrapperCol="{lg: {span:17}, sm: {span: 17} }">
              <BaseInput v-decorator="['subcontractors',{rules: [{   message: ' ' }]}]" disabled />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="合作事项"
                    :labelCol="{lg: {span: 7}, sm: {span: 7}}"
                    :wrapperCol="{lg: {span:17}, sm: {span: 17} }">
              <BaseInput v-decorator="['matters',{rules: [{  message: ' ' }]}]" disabled/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="进场时间"
                    :labelCol="{lg: {span: 7}, sm: {span: 7}}"
                    :wrapperCol="{lg: {span:17}, sm: {span: 17} }">
              <a-date-picker disabled v-decorator="['entryTime',{rules: [{ message: ' ' }]}]" style="width: 100%;" />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="出场时间"
                    :labelCol="{lg: {span: 7}, sm: {span: 7}}"
                    :wrapperCol="{lg: {span:17}, sm: {span: 17} }">
              <a-date-picker @change="outTime" v-decorator="['outTime',{rules: [{ required: true, message: ' ' }]}]" style="width: 100%;" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="出场审批表"
                    :labelCol="{lg: {span: 7}, sm: {span: 7}}"
                    :wrapperCol="{lg: {span:17}, sm: {span: 17} }">
              <l-table @fileArrysData="fileArrysData1"   :businessCode="businessCode"></l-table>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'

// 表单字段
const fields = ['branch','projectName','subcontractors','matters','entryTime', 'outTime']

export default {
  name:'a'+Date.now(),
  props: {
    visible: {
      type: Boolean,
      required: false
    },
    loading: {
      type: Boolean,
      default: () => false
    },
    model: {
      type: Object,
      default: () => null
    }
  },
  data () {
    this.formLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 13 }
      }
    }
    return {
      businessCode:'PM08',
      companyNames: [], // 分公司名称
      projectNames: [], // 项目名称
      form: this.$form.createForm(this)
    }
  },
  created () {

    // 防止表单未注册
    fields.forEach(v => this.form.getFieldDecorator(v))

    // 当 model 发生改变时，为表单设置值
    this.$watch('model', () => {
      this.model && this.form.setFieldsValue(pick(this.model, fields))

    })
  },
  methods:{
    outTime(val){
      this.$emit('outTimes',val.format('YYYY-MM-DD'))
    },
    fileArrysData1(val){
      console.log("返回上传数据：",val)
      this.$emit('fileArrys',val[0].commonId)
    },

  }
}
</script>
